﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MINERP.BLL.Statistics;

namespace MINERP.Statistics.Forms
{
    public partial class FrmDesignerUserStat : Form
    {
        private UserDesignerStatBLL _bll;
        private static FrmDesignerUserStat _instance;

        private FrmDesignerUserStat()
        {
            InitializeComponent();
            deStartTime.DateTime = DateTime.Now.Date;
            deEndTime.DateTime = DateTime.Now;

            //初始化用户组下拉列表

            _bll = new UserDesignerStatBLL();

            cmbWorkGroup.DataSource = _bll.GetGroupList();
            cmbWorkGroup.DisplayMember = "GroupName";
            cmbWorkGroup.ValueMember = "GroupId";
        }

        public static FrmDesignerUserStat GetInstance
        {
            get
            {
                if (_instance == null||_instance.IsDisposed)
                {
                    _instance = new FrmDesignerUserStat();
                }
                return _instance;
            }
        }


        private void btnOK_Click(object sender, EventArgs e)
        {
            btnOK.Enabled = false;
            this.Cursor = Cursors.WaitCursor;

            int groupId = (int)cmbWorkGroup.SelectedValue;
            DateTime startTime = deStartTime.DateTime;
            DateTime endTime = deEndTime.DateTime;
            DataSet dsResult;
            int result = _bll.GetDesignerStat(groupId, startTime, endTime, out dsResult);
            if (result == 1)
            {
                FastReport.Report report = new FastReport.Report();
                dsResult.WriteXml(@"D:\\a.xml", XmlWriteMode.WriteSchema);               
         
                report.Load(Application.StartupPath + @"\\Report\\设计员业绩统计.frx");
                report.RegisterData(dsResult, "Table");
                report.Refresh();
                report.Preview = previewControl1;
                previewControl1.Refresh();
              
                report.Show();
            }
            else
            {
                MessageBox.Show("无记录!");
            }

            this.Cursor = Cursors.Default;
            btnOK.Enabled = true;
        }
    }
}
